﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using COM.DTO;
using NHibernate;
using NHibernate.Criterion;

namespace DAL.DAO
{
    public class AddressDAO
    {
        public static void Add(Address Address)
        {
            {
                using (ISession session = NHibernateHelper.OpenSession())
                using (ITransaction transaction = session.BeginTransaction())
                {
                    session.SaveOrUpdate(Address);
                    transaction.Commit();
                }
            }
        }
        public static void Update(Address Address)
        {
            {
                using (ISession session = NHibernateHelper.OpenSession())
                using (ITransaction transaction = session.BeginTransaction())
                {
                    session.Update(Address);
                    transaction.Commit();
                }
            }
        }

        public static void Remove(Address Address)
        {
            {
                using (ISession session = NHibernateHelper.OpenSession())
                using (ITransaction transaction = session.BeginTransaction())
                {
                    session.Delete(Address);
                    transaction.Commit();
                }
            }
        }
        public static Address getAddressbyId(string addressId)
        {
            using (ISession session = NHibernateHelper.OpenSession())
                return session.Get<Address>(addressId);
        }

        
        /*
        public static List<Address> getAddressbyHotelId(string hotelId)
        {
            using (ISession session = NHibernateHelper.OpenSession())
            {
                var addr = session
                    .CreateCriteria(typeof(Address))
                    .Add(Restrictions.Eq("HotelId", hotelId));
                return addr.List<Address>().ToList();
            }
        }
        public static List<Address> getAddressbyUserId(string UserId)
        {
            using (ISession session = NHibernateHelper.OpenSession())
            {
                var addr = session
                    .CreateCriteria(typeof(Address))
                    .Add(Restrictions.Eq("UserId", UserId));
                return addr.List<Address>().ToList();
            }
        } */
    }
}
